<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户姓名" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交底人" prop="dataPreprocessor">
        <el-select v-model="queryParams.dataPreprocessor" placeholder="请选择技术交底人" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_cme_technicalhandover"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="录入人员" prop="salesman">
        <el-select v-model="queryParams.salesman" placeholder="请选择录入人员" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_cme_ordermen"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['LaserCladding:LaserCladdingOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['LaserCladding:LaserCladdingOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['LaserCladding:LaserCladdingOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['LaserCladding:LaserCladdingOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="LaserCladdingOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="排序" align="center" prop="id" />-->
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="客户姓名" align="center" prop="clientName" />
      <el-table-column label="客户电话" align="center" prop="clientPhone" />
      <el-table-column label="交付日期" align="center" prop="dateReleased" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateReleased, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="录入时间" align="center" prop="inputime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inputime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="技术交底人" align="center" prop="dataPreprocessor">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_cme_technicalhandover" :value="scope.row.dataPreprocessor"/>
        </template>
      </el-table-column>
      <el-table-column label="录入人员" align="center" prop="salesman">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_cme_ordermen" :value="scope.row.salesman"/>
        </template>
      </el-table-column>
      <el-table-column label="技术要求" align="center" prop="technicalRequirements" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['LaserCladding:LaserCladdingOrder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="todetail2(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改LaserCladdingOrder对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单ID" />
        </el-form-item>
        <el-form-item label="客户姓名" prop="clientName">
          <el-input v-model="form.clientName" placeholder="请输入客户姓名" />
        </el-form-item>
        <el-form-item label="客户电话" prop="clientPhone">
          <el-input v-model="form.clientPhone" placeholder="请输入客户电话" />
        </el-form-item>
        <el-form-item label="交付日期" prop="dateReleased">
          <el-date-picker clearable size="small"
            v-model="form.dateReleased"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择交付日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="录入时间" prop="inputime">
          <el-date-picker clearable size="small"
            v-model="form.inputime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择录入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="技术交底人" prop="dataPreprocessor">
          <el-select v-model="form.dataPreprocessor">
            <el-option
              v-for="dict in dict.type.sys_cme_technicalhandover"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="录入人员" prop="salesman">
          <el-select v-model="form.salesman">
            <el-option
              v-for="dict in dict.type.sys_cme_ordermen"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="技术要求" prop="technicalRequirements">
          <el-input v-model="form.technicalRequirements" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="上传" v-if="this.updown">
          <!--<file-upload/>-->
          <file-upload :orderid="form.orderId"/>
        </el-form-item>
        <el-form-item label="下载" v-if="this.updown">
          <el-link   :underline="false">
            <el-button type="primary" @click="getorderfile">获取文件<i class="el-icon-download el-icon--right"></i></el-button>
          </el-link>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLaserCladdingOrder, getLaserCladdingOrder, delLaserCladdingOrder, addLaserCladdingOrder, updateLaserCladdingOrder } from "@/api/LaserCladding/LaserCladdingOrder";
import {download} from "@/utils/request";
import {listCmelasercladding1,getFileInformation} from "@/api/cmelasercladding/claddingurl";
import ElFormItem from "element-ui/packages/form/src/form-item";
import CladdingProcess from "@/views/cmelasercladding/file/CladdingProcess";
import FileUpload from "@/views/cmelasercladding/file/FileUpload"

export default {
  name: "LaserCladdingOrder",
  dicts: ['sys_result', 'sys_is_handling', 'sys_cme_beforeman','sys_cme_ordermen','sys_cme_technicalhandover'],
  components: {
    ElFormItem,
    FileUpload,
    CladdingProcess,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // LaserCladdingOrder表格数据
      LaserCladdingOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //order文件名
      orderfilename: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        clientName: null,
        dataPreprocessor: null,
        salesman: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "订单ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询LaserCladdingOrder列表 */
    getList() {
      this.loading = true;
      listLaserCladdingOrder(this.queryParams).then(response => {
        this.LaserCladdingOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        clientName: null,
        clientPhone: null,
        dateReleased: null,
        inputime: null,
        dataPreprocessor: null,
        salesman: null,
        technicalRequirements: null
      };
      this.resetForm("form");
    },
    /** 跳转到详情页 */
    todetail2(row) {
      const orderid = row.orderId
      this.$router.push({ path: '/Detail2', query: {orderid:orderid} })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.updown = false;
      this.open = true;
      this.title = "添加激光熔覆订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLaserCladdingOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.updown = true;
        this.title = "修改激光熔覆订单";
        //获取路由跳转时的传参
        // let orderid = this.$route.query.orderid
        this.queryParams.orderId =this.form.orderId;
        this.queryParams.oederid = this.form.orderId;
        //获取url原始数据
        listCmelasercladding1(this.queryParams).then(response => {
          this.urlList = response.rows[0];
        });
      });
      //获取文件信息
      getFileInformation(this.queryParams).then(response => {
        this.orderfilename = response.orderfilename;
      });
    },
    //order文件下载
    getorderfile(){
      this.queryParams.resource = this.urlList.claddingUpload;
      download("/cmelasercladding/download/resource", this.queryParams, "激光熔覆原始文件：" + this.queryParams.orderId + this.orderfilename);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLaserCladdingOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLaserCladdingOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
      this.queryParams.orderId = null;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除LaserCladdingOrder编号为"' + ids + '"的数据项？').then(function() {
        return delLaserCladdingOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('LaserCladding/LaserCladdingOrder/export', {
        ...this.queryParams
      }, `LaserCladdingOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
